package com.qf.exception;

import sun.awt.windows.ThemeReader;

import java.util.ArrayList;

/**
 * 演示异常如何处理
 */
public class Demo04 {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"进入冬眠");
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    System.out.println(Thread.currentThread().getName()+"：被打断了");
                    throw new RuntimeException("被打断了");
                }
                System.out.println(Thread.currentThread().getName()+"冬眠结束了");
            }
        });
        thread.setName("bear");
        thread.start();

        Thread.sleep(1000);

        // 打断bear线程的休眠
        thread.interrupt();

        System.out.println("123445");
    }


    public static void method3() throws InterruptedException {
        Thread.sleep(10000);
    }

    public static ArrayList<Integer> method02(){

        ArrayList<Integer> list = new ArrayList<>();

        try {
            list.add(1);
            int a=1/0;
            return list;
        } catch (Exception e) {
//            throw new RuntimeException(e);
            list.add(2);
            return list;
        } finally {
            list.add(3);
        }


    }


    public static int method01(){

        int a = 10;

        try {
            a = 20;
            int b = 1/0;
            return a;
        } catch (Exception e) {
//            throw new RuntimeException(e);
            a = 30;
            return a;
        } finally {
            a = 50;
            System.out.println("finally !!!!!");
//            return a;
        }

    }

}
